package com.nrtms.worker.config;

import com.xxl.job.core.executor.XxlJobExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * xxl-job config
 */
@Configuration
public class XxlJobConfig {
    private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);

    @Bean
    @ConfigurationProperties(prefix = "xxl.job")
    public XxlJobProperties xxlJobProperties() {
        return new XxlJobProperties();
    }

    @Bean(initMethod = "start", destroyMethod = "destroy")
    public XxlJobExecutor xxlJobExecutor(XxlJobProperties xxlJobProperties) {
        XxlJobExecutor xxlJobExecutor = new XxlJobExecutor();
        xxlJobExecutor.setIp(xxlJobProperties.getIp());
        xxlJobExecutor.setPort(xxlJobProperties.getPort());
        xxlJobExecutor.setAppName(xxlJobProperties.getAppname());
        xxlJobExecutor.setAdminAddresses(xxlJobProperties.getAddresses());
        xxlJobExecutor.setLogPath(xxlJobProperties.getLogpath());
        xxlJobExecutor.setAccessToken(xxlJobProperties.getAccessToken());
        logger.info("xxlJobExecutor build success");
        return xxlJobExecutor;
    }

}